package org.zanpu.timer.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.zanpu.timer.thread.interf.ExecutorThread;

import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 定时任务服务主体
 * Created by MD on 2016/12/23.
 */
@Component
public class MainTask {
    private final Logger logger = LoggerFactory.getLogger(MainTask.class);

    @Autowired
    private ExecutorThread executorThread;

    public static Map<String, Long> lastTime = new HashMap<>();
    public static Map<String, Boolean> result = new HashMap<>();

    @Autowired
    private DoTask doTask;


    /**
     * 定制执行任务调度 间隔5秒
     */
    @Scheduled(cron = "*/5 * * * * ?")
    public void run() {
        logger.info("定时触发：" + DateFormat.getDateTimeInstance().format(new Date()));
        executorThread.run(doTask::doTimer);
    }
}
